#include<bits/stdc++.h>
using namespace std;
#define int long long
int T,n,ans,a[120];
void solve(int x){
    int xx=x;
    int neb=0,ner=0,tmp=0;
    int k=1;
    while(k<=n){
        if(x&1){
            if(a[k]==neb)tmp+=neb;
            neb=a[k];
        }else{
            if(a[k]==ner)tmp+=ner;
            ner=a[k];
        }
        k++;
        x>>=1;
    }
    //if(tmp>=ans)cout<<xx<<' ';
    ans=max(ans,tmp);
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin>>T;
    while(T--){
        ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int i=0;i<=(1<<n)-1;i++)solve(i);
        cout<<ans<<'\n';
    }
    return 0;
}
/*

*/
